<?

class sign_recover_action extends action_controller
{
	public function execute()
	{
		helper_html::$meta['title'] = 'Recover password';
	}

	public function execute_post()
	{
		$this->json = array();

		if ( !$user = user_peer::get_by('email', $_POST['email']) )
			return $this->json = array('error' => 'No such email registered');
		
		$d = base64_encode($user['id'] . ';' . md5($user['id'] . $user['email'] . $user['password'] . 'recovery'));
		$activation_url = 'http://' . $_SERVER['SERVER_NAME'] . '/sign/password?d=' . $d;
		$body = 'Greetings!' . "\n" .
				'Please visit the link below to update your password:' . "\n" .
				$activation_url . "\n\n" .
				config::get('email_signature');
		$m = new mail($user['email'], 'Password recovery', $body);
		$m->send();
	}
}